public class Feed extends AtomBase  {

	public List<AtomBase> entry { get; set; }
	public Source s;
	public String totalResults { get; set; }
	public String generator { get; set; }
	public String icon { get; set; }
	public String logo { get; set; }

	public Map<String, Element> extensions;
	 
	public Feed() {
		super();  
	}
	public Feed(String localName) {
		super(localName); 
	}
	 
	public Feed(XmlStreamReader reader) {
		super(reader);
	}
	
	public override void handleStartTag(XmlStreamReader reader, String nodeName) {
		System.debug(LoggingLevel.INFO, '\n\n \t FEED Handle Start Tag \n');
		String nodeText;
		entry = new List<AtomBase>();
		extensions = new Map<String, Element>();
		while (reader.hasNext()) {
	        if (reader.getEventType() == XmlTag.START_ELEMENT) {
				String tagName = reader.getLocalName();
	        	System.debug(LoggingLevel.FINE, '\tStart: ' + tagName + '');
				nodeText = '';
				if (tagName == 'entry') {
					System.debug(LoggingLevel.INFO, '\n\n\t FEED Adding entry...\n');
					//reader.next(); 
					addEntry(new ActivityEntry(reader)); 
				} else if (tagName == 'author') { 
					addAuthor(new Person(reader, tagName));
				} else if (tagName == 'link') {
					addLink(new Link(reader));
				} else if (tagName == 'feed') {
				} else {
					System.debug(LoggingLevel.FINE, '\tSkipping ' + tagName + '');
					System.debug(LoggingLevel.FINE, '\n\nUnhandled tag name: ' + tagName + '\n');
				}
				reader.next();
			} else if (reader.getEventType() == XmlTag.CHARACTERS) {
				if ( ! reader.isWhitespace()) { 
                    nodeText += reader.getText();  // add text to current element
                }
                reader.next(); 
	        } else if (reader.getEventType() == XmlTag.END_ELEMENT) {
	        	System.debug(LoggingLevel.INFO, '\n\n\t FEED handleing end element for ' + reader.getLocalName() + '\n');
	        	System.debug(LoggingLevel.FINE, '\tEnd ' + reader.getLocalName() +'');
	   			if (reader.getLocalName() == 'generator') {
	   				generator = nodeText;
				} else if (reader.getLocalName() == 'icon') {
					icon = nodeText;
				} else if (reader.getLocalName() == 'logo') {
					logo = nodeText;
				} else if (reader.getLocalName() == 'id') {
					System.debug(LoggingLevel.INFO, '\n\n\t SETTING ID TO: ' + nodeText + '\n');
					setId(nodeText);
				} else if (reader.getLocalName() == 'title') {
					setTitle(nodeText);
				} else if (reader.getLocalName() == 'updated') {
					setUpdated(Datetime.valueOf(nodeText.replaceAll('T', ' ')));
				} else if (reader.getLocalName() == 'totalResults') {
					totalResults = nodeText;
				} else { 
	   				//return;
	   			}
	   			reader.next();
	   			if (reader.getLocalName() == nodeName) {
	   				return;
	   			}
	        }
		}		
	}
	
	public List<AtomBase> getEntries() {
		return entry;
	}

	public Feed addEntry(AtomBase entry) {
		this.entry.add(entry);
		return this;
	}

	public AtomBase addEntry() {
		AtomBase e = new AtomBase();
		entry.add(e);
		return e;
	}
	
	public Feed insertEntry(AtomBase entry) {
		this.entry.set(0, entry);
		return this;
	}
	
	public AtomBase insertEntry() {
		AtomBase e = new AtomBase();
		entry.set(0, e);
		return e;
	}
	
	/*public Source getAsSource() {
		Source s = new Source();
		s = this;
		return s;
	}*/
 
	public AtomBase getEntry(String id) {
		for (AtomBase e : entry) {
			if (e.getId() == id) {
				return e;
			}
		}
		return null;
	}	


}